package cn.gtlc.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description TODO
 * @Author zhouwx
 * @Date 2022/9/15
 * @Version -
 */
@Component
public class StringToConverter implements Converter<String, Date> {
    @Override
    public Date convert(String source) {
        try {
            if (StringUtils.isEmpty(source)) {
                return null;
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(source);
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }
}
